/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package openaccessagrotagtagger;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.io.*;
import java.util.*;

import properties.LoadProperties;
import semanticagrotagtagger.ConfigRootPath;
import semanticagrotagtagger.SemanticAgrotagTagger;


public class OpenAccessAgrotagTagger {

      
    // Database Connection Parameters
    public static LoadProperties lp = new LoadProperties(); 
    private static String rootPath =  lp.getRootPath();
    public static String dbName = lp.getDatabaseName();
    public static String dbConnIP = lp.getDatabaseConnectionIP();
    public static String dbConnPort = lp.getDatabaseConnectionPort();
    public static String dbUser = lp.getDatabaseUser();
    public static String dbPwd = lp.getDatabasePwd();
    
    private String tableNameNode = "node";
    private String tableNameBook ="book";
    private static String nidFilePath = rootPath + "Agrotagger/nid/OpenAccessLastNID.txt";
   
    
    public static String dbPath = "jdbc:mysql://" + dbConnIP + ":" + dbConnPort + "/" + dbName + "?" + 
                            "user=" + dbUser +"&password=" + dbPwd;
    public static String attachmentsFolderPath = rootPath + "Agrotagger/uploaded_files/";
    public static String openaccessPath = rootPath + "Agrotagger/uploaded_files/";
    public static String rootPathSemanticAgrotagTagger = rootPath + "Agrotagger/SemanticAgrotagTagger/";

   public String tag_generation(int nid, int noOfTags)
    {

       String tagSet="NULL";

        try {
             try {
                    SemanticAgrotagTagger tagger = new SemanticAgrotagTagger();
                    ConfigRootPath configRootPath = new ConfigRootPath();
                    configRootPath.setRootPath(rootPathSemanticAgrotagTagger);
                        GetFidFromUpload getfid = new GetFidFromUpload();
                        int fid = getfid.getFid(nid);

                        if (fid!=0)
                        {
                            String fileName="";
                            System.out.println("retieve filename  from files table ");
                            GetFilePathFromFiles getfilepath = new GetFilePathFromFiles();
                            fileName = getfilepath.getFileNameAndRemoveSpaces(fid);
                            if (!fileName.isEmpty())
                            {

                                if (fileName.endsWith(".txt") )
                                {
                                    String texttags=null;
                                //     tagSet = tagger.getTagsFromText("/root/Agrotagger/uploaded_files/" + fileName, 10, 10);
                                    tagSet = tagger.getTagsFromText(rootPath + "Agrotagger/uploaded_files/" + fileName, 10, noOfTags);
                                      System.out.println("tTAGS EXTRACTED::::: " + tagSet);
                                }
                                else
                                {
                                    System.out.println("filePath after returning : " + fileName);
                             //       tagSet = tagger.getTagsFromAttachment("/root/Agrotagger/uploaded_files/" + fileName, 10, 10);
                                    tagSet = tagger.getTagsFromAttachment(rootPath + "Agrotagger/uploaded_files/" + fileName, 10, noOfTags);
                                    System.out.println("tTAGS EXTRACTED::::: " + tagSet);
                                }

                                // book
                                // book_chapter
                                // conference_paper
                                // conference_proceedings
                                // journal
                                // miscellaneous


                                UpdateTagsInNodeTable updateTagsNode = new UpdateTagsInNodeTable();
                                updateTagsNode.updateTagsInNodeTable(nid, tagSet);
                            }
                        }

                }
                catch (Exception ex)
                {
                    System.out.println("Exception here :" + ex);
                }
        } catch (Exception ex) {
            System.out.println("Exception: " + ex.getMessage());
        }

        return tagSet;
    } 
} // 